package pl.edu.agh.mwo.model;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;

public class ListingService {

	/**
	 * @param args
	 */
	public static ArrayList<File> getFileList(String fileDirectory) {
		File dir = new File(fileDirectory);
		ArrayList<File> all = new ArrayList<File>();
		addTree(dir, all);

		ArrayList<File> filteredFiles = new ArrayList<File>();
		for (File file : all) {
			if (file.getName().endsWith(".xls")) {
				filteredFiles.add(file);
			}
		}
		return filteredFiles;
	}

	public static void main(String[] args) {

		String fileDirectory = "C:\\Documents and Settings\\Student\\Pulpit\\test";
		ArrayList<File> pliki = getFileList(fileDirectory);

		for (File file : pliki) {
			System.out.println(file.getName());
		}
	}

	static void addTree(File file, Collection<File> all) {
		File[] children = file.listFiles();
		if (children != null) {
			for (File child : children) {
				all.add(child);
				addTree(child, all);
			}
		}
	}
}